package leetcode;

/**
 * 整数反转
 *
 * @author:xufengxiang
 * @date 2023-02-15 19:22
 */
public class Code7 {
    public static int reverse(int x) {
        int max = 214748364;
        int min = -214748364;

        int revert = 0;
        while(x != 0){
            int tmp = x %10;
          if(max < revert ||  (tmp > 7 && revert == max)){
              return  0;
          }

          if(min > revert || (tmp < -8 && revert == min)){
            return  0;
          }
            revert = revert * 10 + x % 10;
            x = x / 10;

        }

        return revert;
    }

    public static void main(String[] args) {
        int x = 123;
        System.out.println(reverse(x));
    }

}
